package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSchoolProject;
import com.ruoyi.system.service.ISysSchoolProjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目管理Controller
 * 
 * @author 杨皓焜
 * @date 2021-02-06
 */
@RestController
@RequestMapping("/system/project")
public class SysSchoolProjectController extends BaseController
{
    @Autowired
    private ISysSchoolProjectService sysSchoolProjectService;

    /**
     * 查询项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSchoolProject sysSchoolProject)
    {
        startPage();
        List<SysSchoolProject> list = sysSchoolProjectService.selectSysSchoolProjectList(sysSchoolProject);
        return getDataTable(list);
    }

    /**
     * 导出项目管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:project:export')")
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysSchoolProject sysSchoolProject)
    {
        List<SysSchoolProject> list = sysSchoolProjectService.selectSysSchoolProjectList(sysSchoolProject);
        ExcelUtil<SysSchoolProject> util = new ExcelUtil<SysSchoolProject>(SysSchoolProject.class);
        return util.exportExcel(list, "project");
    }

    @PostMapping("/setNum")
    public AjaxResult setNum(@RequestBody Integer num) {
        return AjaxResult.success(sysSchoolProjectService.setProjectNum(num));
    }

    /**
     * 获取项目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return AjaxResult.success(sysSchoolProjectService.selectSysSchoolProjectById(projectId));
    }

    /**
     * 新增项目管理
     */
    @PreAuthorize("@ss.hasPermi('system:project:add')")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSchoolProject sysSchoolProject)
    {
        return toAjax(sysSchoolProjectService.insertSysSchoolProject(sysSchoolProject));
    }

    /**
     * 修改项目管理
     */
    @PreAuthorize("@ss.hasPermi('system:project:edit')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSchoolProject sysSchoolProject)
    {
        return toAjax(sysSchoolProjectService.updateSysSchoolProject(sysSchoolProject));
    }

    /**
     * 删除项目管理
     */
    @PreAuthorize("@ss.hasPermi('system:project:remove')")
    @Log(title = "项目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(sysSchoolProjectService.deleteSysSchoolProjectByIds(projectIds));
    }
}
